package com.itic.market.mobile.project;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.utils.StringHelper;
import com.itic.market.mobile.base.BaseMobileInterface;


/**
 * 用户登入接口类
 * @author 许小宝
 * 2017年07月25日  14时11分
 */
@Controller
@RequestMapping(value="/mobile/project")
public class MarketProjectInterface
     extends BaseMobileInterface {
	
    /**
     * 分享版本号类型
     * @return
     */
    @RequestMapping(value="/shareType")
    @ResponseBody
    public Map<String,Object> shareType( HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		String shareType = sysSettingService.getByKey("MARKET_SHARE_TYPE");
    	    
    		resultMap.put(DATA, shareType);
    		
    		result = SUCCESS;
    		
    		errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG; 
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE; 
        	errorMsg = SERVER_ERROR_MSG;
        	e.printStackTrace();
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    /**
     * 版本升级
     * @return
     */
    @RequestMapping(value="/version")
    @ResponseBody
    public Map<String,Object> version( HttpServletRequest request,HttpServletResponse response , String type ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		String shareType = "nuknown";
    		if( StringHelper.isNotBlank(type) ){
    			if( "ios".equals(type) ){
    				shareType = sysSettingService.getByKey("PROJECT_VERSION_IOS");
    			}
    			if( "android".equals(type) ){
    				shareType = sysSettingService.getByKey("PROJECT_VERSION_ANDROID");
    			}
    		}
    		resultMap.put(DATA, shareType);
    		result = SUCCESS;
    		errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG; 
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE; 
        	errorMsg = SERVER_ERROR_MSG;
        	e.printStackTrace();
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    /**
     * 版本升级
     * @return
     */
    @RequestMapping(value="/version2")
    @ResponseBody
    public Map<String,Object> version2( HttpServletRequest request,HttpServletResponse response , String type ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		
    		String shareType = "nuknown";
    		if( StringHelper.isNotBlank(type) ){
    			if( "ios".equals(type) ){
    				shareType = sysSettingService.getByKey("PROJECT_VERSION2_IOS");
    			}
    			if( "android".equals(type) ){
    				shareType = sysSettingService.getByKey("PROJECT_VERSION2_ANDROID");
    			}
    		}
    		resultMap.put(DATA, shareType);
    		result = SUCCESS;
    		errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG; 
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE; 
        	errorMsg = SERVER_ERROR_MSG;
        	e.printStackTrace();
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
}